﻿@{
    ViewBag.Title = "deliveryInList";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>  
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
<body>
   <form id="form1" runat="server" method="post" style="height: 100%">
    
    @Html.Partial("~/Views/Modular/BillListToolbar.cshtml")
    
    <div id = "DivHeader">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">单据日期：</td>
                <td width ="310px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="70px" align="right">配送门店：</td>
                <td width ="190px">    
                     @Html.Partial("~/Views/Delivery/LookupStockRelevant.cshtml")                      
                </td>
                <td width ="70px" align="right"></td>
                <td width ="150px">
                </td>
            </tr>
            <tr>
                <td width ="70px" align="right">单据编号：</td>
                <td width ="310px">
                    <input name="FBillNo" class="mini-textbox" style="width:308px;"/>
                </td>
                <td width ="70px" align="right">收货门店：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")  
                </td>
                <td width ="70px" align="right">审核状态：</td>
                <td width ="150px">
                    <input id="comCheckFlag" name ="FCheckFlag" class="mini-combobox" style="width:100px;" 
                    showNullItem="false" required="true" allowInput="false" align="left" data ="dCheckFlag"/>  
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" borderStyle="border:1;"pageSize="15"
            url="../Report/GetBillList"
            allowCellSelect="true" allowCellEdit="true" showSummaryRow="true" ondrawsummarycell="onDrawSummaryCell"
            fitColumns="false" onrowdblclick="editBill" sortMode="client" onselectionchanged="onSelectionChanged">
            <div property="columns">
                <div type="checkcolumn" ></div>  
                <div field="FBillNo" width="120" headerAlign="center">单据编号</div>    
                <div field="FDate" name="FDate" width="90px" headerAlign="center">单据日期</div> 
                <div field="FQty" name="FQty" width="70" headerAlign="center" align="right" numberFormat="#,0.00">数量</div>
                <div field="FAmount" name="FAmount" width="90" headerAlign="center" align="right" numberFormat="#,0.00">金额</div>
                <div field="FCheckName" width="70" headerAlign="center">审核标志</div>
                <div field="FGetStockName" width="150" headerAlign="center">配送门店</div>
                <div field="FSetStockName" width="150" headerAlign="center">收货门店</div>
                <div field="FUserName" width="80" headerAlign="center">用户名称</div>
                <div field="FRemark" width="120" headerAlign="center">备注</div>    
            </div>
        </div>  
    </div>
    
                          <input id="type" name="type" value="@ViewBag.type" type="hidden"/>
    <script type="text/javascript">

        var dCheckFlag = [{ "id": "0", "text": "全部" },
                         { "id": "1", "text": "未审核" },
                         { "id": "2", "text": "已审核" }]

        mini.parse();
        var form = new mini.Form("form1");
        var grid = mini.get("datagrid1");
        var uID = parent.window.getSystemAppID();
        var hdatatype = $("#type").val();
        var sumFields = "FQty,FAmount";

        function FormShown() {
            var nowDate = new Date();
            mini.getbyName("FDate1").setValue(nowDate);
            mini.getbyName("FDate2").setValue(nowDate);
            mini.getbyName("FCheckFlag").select(0);
            search();
        }

        function editBill() {
            if (!mini.get("editbill").getVisible()) return;
            var row = grid.getSelected();
            if (row) {
                parent.window.showTabByIdEx('83','DeliveryIn', '配送入库', '../Delivery/DeliveryIn?datatype=11&billid=' + row.KInterID);
            }
        }

        function removeBill() {
            var row = grid.getSelected();
            if (row) {
                var mCheckFlag = row.FCheckFlag;
                if (!mCheckFlag) {
                    mini.confirm("确定要删除该单据吗？", "提示",
                        function (action) {
                            if (action == "ok") {
                                SetRemoveBill(row);
                            }
                        }
                   );
                }
                else {
                    mini.alert("已审核的单据不能删除!");
                }
            }
        }

        function SetRemoveBill(row) {
            var json = "[{";
            json = json + "'KInterID':'" + row.KInterID + "',";
            json = json + "'FDataType':'" + row.FDataType + "',";
            json = json + "'FSystemAppID':'" + uID + "'}]";
            $.ajax({
                url: '../Bill/RemoveBillData',
                data: { mdatajson: json },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    if (ret.id != -1) {
                        grid.removeRow(row, true);
                        mini.showMessageBox({
                            showModal: false, width: 250, title: "提示", iconCls: "mini-messagebox-info",
                            message: ret.Status, timeout: 3000, x: "right", y: "bottom"
                        });
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }

        function search() {
            var cDate1 = mini.getbyName("FDate1").getFormValue();
            var cDate2 = mini.getbyName("FDate2").getFormValue();
            var mCheckFlag = mini.getbyName("FCheckFlag").getValue();
            var mBillNo = mini.getbyName("FBillNo").getValue();
            var mStockID = mini.getbyName("FStockID").getValue();
            var FRStockID = mini.getbyName("FRStockID").getValue();

            var json = "[{";
            json = json + '"mListType":' + '"' + hdatatype + '",';//列表类型
            json = json + '"mSystemAppID":' + '"' + uID + '",';
            json = json + '"mDate1":' + '"' + cDate1 + '",';
            json = json + '"mDate2":' + '"' + cDate2 + '",';
            json = json + '"mCheckFlag":' + '"' + mCheckFlag + '",';
            json = json + '"mStockID":' + '"' + FRStockID + '",';
            json = json + '"mRStockID":' + '"' + mStockID + '",';
            json = json + '"mBillNo":' + '"' + mBillNo + '"';
            json = json + "}]";

            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;//导出
        }

        function onSelectionChanged(e) {
            var mgrid = e.sender;
            var record = mgrid.getSelected();
            if (record) {
                var mCheckFlag = record.FCheckFlag;
                if (!mCheckFlag) {
                    mini.get("removebill").setEnabled(true);
                }
                else {
                    mini.get("removebill").setEnabled(false);
                }
            }
        }

        function printdata() {
            var url = "../Report/PrintReport";
            mini.open({
                url: url,
                title: "打印", width: 1000, height: 700,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var NoneDisplayCol = [0];
                    var headtext = " 配送入库列表";
                    iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, parent.window.getSystemCompany() + headtext);
                }
            });
        }

    </script>

    </form>
</body>
